<template>
	<view class="params">
		<uni-section type="line">
			<uni-collapse accordion v-model="current" @change="tabChange">
				<uni-collapse-item title="参数设置" v-show="permission('applet:equip:setting')"
					:disabled="paramCode==320||paramCode==500">
					<view class="param-content">
						<view v-if="equipTypeCode == 'EC'">
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check1')">
									<checkbox :checked="checkList.check1" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>快充</text>
								<switch color="#51b7b9" @change="switchChange($event,'06010014')"
									:checked="boxForm['06010014']" style="transform:scale(0.7)" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check2')">
									<checkbox :checked="checkList.check2" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>备电</text>
								<switch color="#51b7b9" :checked="boxForm['06010015']"
									@change="switchChange($event,'06010015')" style="transform:scale(0.7)" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check3')">
									<checkbox :checked="checkList.check3" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>整流单元休眠</text>
								<switch color="#51b7b9" :checked="boxForm['06010023']"
									@change="switchChange($event,'06010023')" style="transform:scale(0.7)" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check4')">
									<checkbox :checked="checkList.check4" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>电子锁反馈类型</text>
								<uni-data-select class="sliders" placeholder="请选择电子锁反馈类型" v-model="boxForm['06010007']"
									:localdata="getLockOption"></uni-data-select>
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check5')">
									<checkbox :checked="checkList.check5" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>门轴</text>
								<uni-data-select class="sliders" style="width: 50%;" placeholder="请选择门轴"
									:disabled="!boxForm['06010008'] || isShow" v-model="boxForm['06010009']"
									:localdata="getLockOption"></uni-data-select>
								<switch color="#51b7b9" :checked="boxForm['06010008']"
									@change="switchChange($event,'06010008')" style="transform:scale(0.7)" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check6')">
									<checkbox :checked="checkList.check6" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>电池在位模式</text>
								<uni-data-select class="sliders" placeholder="请选择电池在位模式" v-model="boxForm['06010011']"
									:localdata="batteryIsOn"></uni-data-select>
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check7')">
									<checkbox :checked="checkList.check7" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>灭火器反馈类型</text>
								<uni-data-select class="sliders" placeholder="请选择灭火器反馈类型" v-model="boxForm['06010022']"
									:localdata="getLockOption"></uni-data-select>
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check8')">
									<checkbox :checked="checkList.check8" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>消防模式</text>
								<uni-data-select class="sliders" placeholder="请选择消防模式" v-model="boxForm['06010024']"
									:localdata="getLockOption"></uni-data-select>
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check9')">
									<checkbox :checked="checkList.check9" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>系统启动散热温度</text>
								<input v-model="boxForm['06010016']" class="uni-input" type="digit"
									@input="onKeyInput($event,'06010016')" placeholder="请输入系统启动散热温度" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check10')">
									<checkbox :checked="checkList.check10" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>系统停止散热温度</text>
								<input v-model="boxForm['06010017']" class="uni-input" type="digit"
									@input="onKeyInput($event,'06010017')" placeholder="请输入系统停止散热温度" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check11')">
									<checkbox :checked="checkList.check11" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>启动整柜加热温度</text>
								<input v-model="boxForm['06010018']" class="uni-input" type="digit"
									@input="onKeyInput($event,'06010018')" placeholder="请输入启动整柜加热温度" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check12')">
									<checkbox :checked="checkList.check12" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>停止整柜加热温度</text>
								<input v-model="boxForm['06010019']" class="uni-input" type="digit"
									@input="onKeyInput($event,'06010019')" placeholder="请输入停止整柜加热温度" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check13')">
									<checkbox :checked="checkList.check13" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>启动单仓加热温度</text>
								<input v-model="boxForm['06010020']" class="uni-input" type="digit"
									@input="onKeyInput($event,'06010020')" placeholder="请输入启动单仓加热温度" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check14')">
									<checkbox :checked="checkList.check14" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>停止单仓加热温度</text>
								<input v-model="boxForm['06010021']" class="uni-input" type="digit"
									@input="onKeyInput($event,'06010021')" placeholder="请输入停止单仓加热温度" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check15')">
									<checkbox :checked="checkList.check15" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>满电阈值</text>
								<input v-model="boxForm['06010031']" class="uni-input" type="digit"
									@input="onKeyInput($event,'06010031')" placeholder="请输入满电阈值" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check16')">
									<checkbox :checked="checkList.check16" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>设备SN码</text>
								<textarea v-model="boxForm['06010025']" class="uni-input textarea-sn"
									placeholder="请输入设备SN码" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check17')">
									<checkbox :checked="checkList.check17" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>有序充电</text>
								<input v-model="boxForm['06010027']" class="uni-input" placeholder="请输入有序充电" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check18')">
									<checkbox :checked="checkList.check18" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>电池容量区分</text>
								<switch color="#51b7b9" @change="switchChange($event,'06010028')"
									:checked="boxForm['06010028']" style="transform:scale(0.7)" />
								<!-- <input v-model="boxForm['06010028']" class="uni-input" placeholder="请输入电池容量区分" /> -->
							</view>
							<!-- <view class="param-one">
							<checkbox-group @change="checkboxChange($event,'check19')">
								<checkbox :checked="checkList.check19" color="#51b7b9" style="transform:scale(0.7)" />
							</checkbox-group>
							<text>邮政密码</text>
							<input v-model="boxForm['06010029']" class="uni-input" placeholder="请输入邮政密码" />
						</view> -->
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check20')">
									<checkbox :checked="checkList.check20" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>管理员密码</text>
								<input v-model="boxForm['06010030']" @input="onPasswordInput('06010030')" class="uni-input" placeholder="请输入管理员密码" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check21')">
									<checkbox :checked="checkList.check21" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>喇叭音量设置</text>
								<slider class="sliders" :value="boxForm['06010032']" @change="sliderChange" min="0"
									max="100" show-value block-size="10" block-color="#51b7b9" />
							</view>
						</view>
						<!-- 充电堆参数 -->
						<view v-else-if="equipTypeCode == 'CS'">
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check1')">
									<checkbox :checked="checkList.check1" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>总功率限制值</text>
								<input v-model="boxForm2['07010007']" class="uni-input" placeholder="请输入总功率限制值" />
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check2')">
									<checkbox :checked="checkList.check2" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>充电堆类型</text>
								<uni-data-select class="sliders" placeholder="请选择充电堆类型" v-model="boxForm2['07010008']"
									:localdata="CHARGING_TYPE"></uni-data-select>
							</view>
							<view class="param-one">
								<checkbox-group @change="checkboxChange($event,'check3')">
									<checkbox :checked="checkList.check3" color="#51b7b9"
										style="transform:scale(0.7)" />
								</checkbox-group>
								<text>设备SN码</text>
								<input v-model="boxForm2['07010042']" class="uni-input" placeholder="请输入设备SN码" />
							</view>
						</view>
						<view class="operate_btns">
							<button type="default" size="mini" @click="isRefresh">手动刷新</button>
							<button class="set_btn" type="default" size="mini" @click="isSetting">设置</button>
						</view>
					</view>
				</uni-collapse-item>
				<uni-collapse-item title="运营平台链接参数" v-show="permission('applet:equip:connection')"
					:disabled="paramCode==320||paramCode==500">
					<view class="param-content">
						<view class="param-one">
							<text class="labels">服务地址</text>
							<input v-model="operateForm.url" class="uni-input inputs" placeholder="请输入服务地址" />
						</view>
						<view class="param-one">
							<text class="labels">端口</text>
							<input v-model="operateForm.port" class="uni-input inputs" type="digit"
								placeholder="请输入端口" />
						</view>
						<view class="param-one">
							<text class="labels">用户名</text>
							<input v-model="operateForm.username" class="uni-input inputs" placeholder="请输入用户名" />
						</view>
						<view class="param-one">
							<text class="labels">密码</text>
							<input v-model="operateForm.password" @input="onOperateInput('password')" class="uni-input inputs" placeholder="请输入密码" />
						</view>
						<view class="param-one">
							<text class="labels">产品密钥</text>
							<input v-model="operateForm.productKey" @input="onOperateInput('productKey')" class="uni-input inputs" placeholder="请输入产品密钥" />
						</view>
						<view class="param-one">
							<text class="labels">设备名称</text>
							<input v-model="operateForm.deviceName" class="uni-input inputs" placeholder="请输入设备名称" />
						</view>
						<view class="param-one">
							<text class="labels">设备密钥</text>
							<input v-model="operateForm.deviceSecret" @input="onOperateInput('deviceSecret')" class="uni-input inputs" placeholder="请输入设备密钥" />
						</view>
						<view class="operate_btns">
							<button type="default" size="mini" @click="isRefresh">手动刷新</button>
							<button class="set_btn" type="default" size="mini" @click="doRunParam">设置</button>
						</view>
					</view>
				</uni-collapse-item>
				<uni-collapse-item title="日志" v-show="permission('applet:equip:logextract')"
					:disabled="paramCode==320||paramCode==500">
					<view class="param-content">
						<view class="param-one">
							<text class="mails">日志类型</text>
							<uni-data-select class="sliders" placeholder="请选择日志类型"
								v-model="ruleForm.logExtractParam.level" :localdata="logOption" @change="levelChange">
							</uni-data-select>
						</view>
						<view class="param-one">
							<text class="mails">开始时间</text>
							<uni-datetime-picker class="datepicker" type="date" placeholder="请选择开始时间" :end="startRange"
								:clear-icon="false" v-model="ruleForm.logExtractParam.startTime" />
						</view>
						<view class="param-one">
							<text class="mails">结束时间</text>
							<uni-datetime-picker class="datepicker" type="date" placeholder="请选择结束时间"
								:end="new Date().getTime()" :clear-icon="false"
								v-model="ruleForm.logExtractParam.endTime" @change="endTimeChange" />
						</view>
						<view class="param-one">
							<text class="mails">接收日志邮箱</text>
							<input class="input" v-model="ruleForm.receiveEmail" type="text" placeholder="请输入接收日志邮箱" />
						</view>
						<view class="log_tips">
							请勿频繁操作，注意流量是否即将超限！！！
						</view>
						<view class="operate_btns">
							<button class="set_btn" type="default" size="mini" @click="isTract">提取</button>
						</view>
					</view>
				</uni-collapse-item>
				<uni-collapse-item title="升级" v-show="permission('applet:equip:upgrade')"
					:disabled="paramCode==320||paramCode==500">
					<view class="param-content">
						<view class="param-one">
							<text class="update-labels">升级部件</text>
							<uni-data-select class="sliders" placeholder="请选择升级部件" v-model="updateForm.partType"
								:localdata="partOption" @change="partTypeChange"></uni-data-select>
						</view>
						<view class="param-one">
							<text class="update-labels">版本</text>
							<uni-data-select class="sliders" placeholder="请选择版本" :disabled="!updateForm.partType"
								v-model="updateForm.softwareVersionId" :localdata="versionOption"
								@change="versionChange"></uni-data-select>
							<uni-icons @click="showHelp" color="#707070" class="help_icon" type="help" size="30">
							</uni-icons>
						</view>
						<view class="operate_btns update_btns">
							<button class="set_btn update_btn" type="default" size="mini" @click="isUpdate">升级</button>
						</view>
						<view class="param-one" v-if="updateResult.status">
							<text class="update-labels">升级通讯结果</text>
							<text class="update-inputs">{{resultData[updateResult.status]}}</text>
						</view>
						<view class="param-one" v-if="updateResult.reason">
							<text class="update-labels">&nbsp;描述</text>
							<text class="update-inputs">{{updateResult.reason}}</text>
						</view>
						<view class="operate_btns update_btns">
							<button class="set_btn update_btn" type="default" size="mini"
								@click="isSearchVersion">查询版本</button>
						</view>
						<view class="versions">{{updateResult.equipSoftwareVersions | formatVersion}}</view>
						<view class="log_tips">
							升级后版本号获取需手动刷新。
							如退出本页面请至升级记录或者查询功能中查询版本信息。
						</view>
					</view>
				</uni-collapse-item>

				<uni-collapse-item title="影像提取" v-show="permission('applet:equip:extract')"
					:disabled="paramCode==320||paramCode==500">
					<view class="param-content">
						<view class="param-one extract-one">
							<text class="mails">操作指令</text>
							<uni-data-select class="sliders" placeholder="请选择操作指令"
								v-model="extractForm.cameraExtractParam.value" :localdata="operateList"
								@change="operateChange" style="width:74%">
							</uni-data-select>
						</view>

						<view class="param-one extract-one">
							<text class="mails">提取日期</text>
							<uni-datetime-picker ref="datePickerRef" class="datepicker" type="date"
								placeholder="请选择提取日期" :end="new Date().getTime()" :clear-icon="false"
								v-model="extractForm.startDate"
								:disabled="extractForm.cameraExtractParam.value == '0'" />
						</view>
						<view class="log_tips">
							注：建议提取开始时间和结束时间不超过5分钟！！！
						</view>
						<view class="param-one extract-one">
							<text class="mails">提取时间</text>
							<picker mode="time" :value="extractForm.tractDate[0]" @change="freeStartChange"
								style="display: inline-block; margin-right: 20px;">
								<view class="uni-input" v-if="extractForm.tractDate[0]"
									style="color: #000000!important; border-bottom: 1px solid #E5E5E5; text-align: center; padding: 5rpx 60rpx 8rpx 10rpx; display: inline-block;">
									{{extractForm.tractDate[0]}}
								</view>
								<view class="uni-input" v-else
									style="color: #BEBEBE;font-size:24rpx;border-bottom: 1px solid #E5E5E5;">
									选择开始时间
								</view>
							</picker>
							至

							<picker mode="time" :value="extractForm.tractDate[1]" @change="freeEndChange"
								style="display: inline-block; margin-left: 20px;">
								<view class="uni-input" v-if="extractForm.tractDate[1]"
									style="color: #000000!important; border-bottom: 1px solid #E5E5E5; text-align: center; padding: 5rpx 60rpx 8rpx 10rpx; display: inline-block;">
									{{extractForm.tractDate[1]}}
								</view>
								<view class="uni-input" v-else
									style="color: #BEBEBE;font-size:24rpx;border-bottom: 1px solid #E5E5E5;">
									选择结束时间
								</view>
							</picker>
							<uni-icons type="clear" size="20" color="#666666" v-if="extractForm.tractDate.length>0"
								@click="clearOccupyTime"></uni-icons>
						</view>
						<view class="operate_btns">
							<button class="set_btn" type="default" size="mini" @click="isAddExtract">新增</button>
						</view>
					</view>
				</uni-collapse-item>

				<uni-collapse-item title="开通录入" v-show="permission('applet:equip:open')"
					:disabled="paramCode==320||paramCode==500">
					<view class="param-content">
						<view class="param-one">
							<text class="labels">设备型号</text>
							<uni-data-select class="sliders" placeholder="请选择设备型号" v-model="dialogForm.equipModelId"
								:localdata="modelOption"></uni-data-select>
						</view>
						<view class="param-one">
							<text class="labels">厂商</text>
							<input class="inputs" v-model="dialogForm.organizationName" type="text" disabled />
						</view>
						<view class="param-one">
							<text class="labels">业务状态</text>
							<uni-data-select class="sliders" placeholder="请选择业务状态" v-model="dialogForm.status"
								:localdata="status"></uni-data-select>
						</view>
						<view class="param-one" @click="moveToLocation">
							<text class="labels">详细地址</text>
							<view class="address">
								{{dialogForm.address?dialogForm.address:""}}
							</view>
						</view>
						<view class="operate_btns">
							<button class="set_btn" type="default" size="mini" @click="isEditEquip">保存</button>
						</view>
					</view>
				</uni-collapse-item>
			</uni-collapse>
		</uni-section>
	</view>
</template>
<script>
	import {
		getLockOption,
		batteryIsOn,
		mapKy,
		AMAP_KEY,
		CHARGING_TYPE
	} from "@/common/config.js";
	import {
		equipment,
		loglevel,
		models,
		logextrace,
		partType,
		softwareVersion,
		updated
	} from "@/api/my.js";
	import {
		removeNullUndefined
	} from "@/common/index.js";
	import {
		mapState,
	} from 'vuex';
	import {
		permission
	} from "@/common/permission.js";
	import {
		GPS
	} from "@/common/GPS.js";
	export default {
		props: {
			equipId: {
				type: String,
				value: "",
			},
			equipCode: {
				type: String,
				value: "",
			},
			paramCode: {
				type: Number,
				value: 500
			},
		},
		data() {
			return {
				getLockOption: getLockOption,
				batteryIsOn: batteryIsOn,
				CHARGING_TYPE:CHARGING_TYPE,

				boxForm: {
					"06010014": 0,
					"06010015": 0,
					"06010023": 0,
					"06010007": undefined,
					"06010009": undefined,
					"06010011": undefined,
					"06010022": undefined,
					"06010024": undefined,
					"06010016": undefined,
					"06010017": undefined,
					"06010018": undefined,
					"06010019": undefined,
					"06010020": undefined,
					"06010021": undefined,
					"06010031": undefined,
					"06010025": undefined,
					"06010027": undefined,
					"06010028": undefined,
					"06010029": undefined,
					"06010030": undefined,
					"06010032": 0,
					"06010008": 0,
				},
				operateForm: {
					deviceName: "",
					deviceSecret: "",
					password: "",
					port: "",
					productKey: "",
					url: "",
					username: "",
				},
				checkList: {
					check1: false,
					check2: false,
					check3: false,
					check4: false,
					check5: false,
					check6: false,
					check7: false,
					check8: false,
					check9: false,
					check10: false,
					check11: false,
					check12: false,
					check13: false,
					check14: false,
					check15: false,
					check16: false,
					check17: false,
					check18: false,
					check19: false,
					check20: false,
					check21: false,
				},
				current: null,
				logOption: [],
				modelOption: [],

				ruleForm: {
					equipCode: "",
					equipClassify: "",
					receiveEmail: "",
					logExtractParam: {
						startTime: "",
						endTime: "",
						level: "",
						filename: "",
					},
				},
				fileType: "", //查询级别fileType
				dialogForm: {
					equipModelId: "",
					operatorId: "",
					status: "",
					regionCode: "",
					lng: "",
					lat: "",
					address: "",
				},
				status: [], //业务状态
				partOption: [], //部件
				versionOption: [], //版本
				currentVersion: {}, //当前选中版本

				updateForm: {
					partType: "",
					softwareVersionId: "",
				},
				updateResult: {}, //升级结果
				resultData: {},
				permission: permission,

				operateList: [],
				extractForm: {
					equipId: "",
					equipCode: "",
					tractDate: ["", ""],
					startDate: "",
					cameraExtractParam: {
						value: "",
						endTime: "",
						startTime: "",
					},
				},

				extractDateRange: [], //提取时间
				// 充电堆参数
				boxForm2: {
					"07010007": undefined,
					"07010008": undefined,
					"07010042": undefined,
				},
			}
		},
		filters: {
			formatVersion(arr) {
				if (arr && arr.length > 0) {
					let arrayTwo = Object.values(
						arr.reduce((res, item) => {
							res[item.partType] ?
								res[item.partType].push(item) :
								(res[item.partType] = [item]);
							return res;
						}, {})
					);
					let jsons = "";
					arrayTwo.map((item, index) => {
						jsons += item[0].partTypeName != null ? item[0].partTypeName : "";
						item.filter((qq, inx) => {
							jsons += qq.version;
							if (inx < item.length - 1) jsons += " | ";
						});
						if (index < arrayTwo.length - 1) jsons += "；";
					});
					return jsons;
				} else {
					return "";
				}
			}
		},
		computed: {
			...mapState(['enums', 'equipTypeCode']),
			startRange() {
				let endTime = new Date(this.ruleForm.logExtractParam.endTime).getTime();
				let nowTime = new Date().getTime();
				if (nowTime >= endTime) {
					return endTime;
				}
				return nowTime;
			},
		},
		watch: {
			enums: {
				async handler(val) {
					this.status = val.EQUIP_STATUS.map(item => {
						return {
							text: item.label,
							value: item.code
						}
					});
					val.EQUIP_OPERATE_RESULT_STATUS.forEach(item => {
						this.resultData[item.code] = item.label;
					});

					this.operateList = val.EQUIP_CAMERA_EXTRACT_LOG_TYPE.map(item => {
						return {
							text: item.label,
							value: item.code
						}
					});
				},
				immediate: true,
			},

		},

		methods: {
			switchChange(e, key) {
				let value = e.detail.value;
				this.boxForm[key] = value;
			},
			checkboxChange(e, key) {
				let value = e.detail.value;
				let check = value.length > 0 ? true : false;
				this.$set(this.checkList, key, check);
			},
			onPasswordInput(type){
				setTimeout(() => {
					this.boxForm[type] = this.boxForm[type].replace(/\s+/g, '');
					this.boxForm[type] = this.boxForm[type].replace(/[\u4E00-\u9FA5]/g,'')
				}, 10)
			},
			onOperateInput(type){
				setTimeout(() => {
					this.operateForm[type] = this.operateForm[type].replace(/\s+/g, '');
					this.operateForm[type] = this.operateForm[type].replace(/[\u4E00-\u9FA5]/g,'')
				}, 10)
			},
			async tabChange(e) {
				this.current = e;
				if (e == '0' || e == '1') {
					this.doRead();
				} else if (e == '2' && this.logOption.length == 0) {
					const logoption = await loglevel(`/all?equipClassify=${this.equipTypeCode}`, 'post');

					this.logOption = logoption.data.map(item => {
						return {
							text: item.name,
							value: item.code,
							fileType: item.fileType
						}
					});
				} else if (e == '3') {
					if (this.partOption.length == 0) {
						this.getPartType();
					}
				} else if (e == '5') {
					// 获取详情信息
					this.equipDetail();
					if (this.modelOption.length == 0) {
						this.getModelOption();
					}
				}
			},
			equipDetail() {
				equipment(`/${this.equipId}`, "get").then((res) => {
					const {
						data
					} = res;
					this.dialogForm = data;
				})
			},
			sliderChange(e) {
				let value = e.detail.value;
				this.$set(this.boxForm, '06010032', value);
			},
			isRefresh() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确认要手动刷新吗？',
					success(res) {
						if (res.confirm) {
							that.resetData();
							that.doRead();
						} else {
							// 执行取消后的操作
						}
					}
				})
			},
			resetData() {
				if (this.current == '0') {
					for (const key in this.boxForm) {
						this.boxForm[key] = undefined;
					}
					for (const key in this.checkList) {
						this.checkList[key] = false;
					}
				} else {
					for (const key in this.operateForm) {
						this.operateForm[key] = "";
					}
				}
			},
			isSetting() {
				let that = this;
				let isChecked = {};
				if (this.equipTypeCode == 'EC') { //换电柜
					Object.values(this.checkList).map((item, index) => {
						Object.keys(this.boxForm).filter((pp, inx) => {
							if (item && index == inx) {
								isChecked[pp] = this.boxForm[pp];
							}
						});
					});
				} else if (this.equipTypeCode == 'CS') { //充电堆
					Object.values(this.checkList).map((item, index) => {
						Object.keys(this.boxForm2).filter((pp, inx) => {
							if (item && index == inx) {
								isChecked[pp] = this.boxForm2[pp];
							}
						});
					});
				}
				if (this.checkList.check5) {
					isChecked['06010008'] = this.boxForm['06010008'];
				}
				if (this.current == "0" && Object.keys(isChecked).length == 0) {
					this.$Toast.none("请勾选需要设置的参数！");
					return;
				} else if (
					this.current == "0" &&
					!Object.values(isChecked).every((item) => item || item == "0")
				) {
					this.$Toast.none("请设置已勾选的参数值！");
					return;
				} else if (this.current == "0") {
					uni.showModal({
						title: '提示',
						content: '确认要设置参数信息吗？',
						success(res) {
							if (res.confirm) {
								that.doSetting(isChecked);
							}
						}
					})
				} else if (this.current == "1") {
					uni.showModal({
						title: '提示',
						content: '确定要设置运营平台链接参数吗？',
						success(res) {
							if (res.confirm) {
								that.doRunParam();
							}
						}
					})
				}
			},
			doRead() {
				this.$Toast.loading('加载中~')
				let params = {
					entitys: [],
					equipId: this.equipId,
				};
				switch (this.current) {
					case '0':
						params.entitys = [];
						if (this.equipTypeCode == 'EC') { //换电柜参数
							for (const key in this.boxForm) {
								params.entitys.push({
									id: key
								});
							}
						} else if (this.equipTypeCode == 'CS') { //充电堆
							for (const key in this.boxForm2) {
								params.entitys.push({
									id: key
								});
							}
						}
						break;
					case '1':
						params.entitys = [];
						for (const key in this.operateForm) {
							params.entitys = [{
								id: "06010049"
							}, {
								id: "06010050"
							}];
						}
						break;
				}

				equipment("/operate/param/read", "post", params)
					.then((res) => {
						uni.hideLoading();
						let datas = res.data;
						datas.forEach((item) => {
							switch (this.current) {
								case '0':
									if (this.equipTypeCode == 'EC') { //换电柜参数
										for (const key in this.boxForm) {
											if (item.id == "06010032") item.value = +item.value;
											if (key == item.id) {
												if (key == '06010014' || key == '06010015' || key ==
													'06010023' ||
													key == '06010008') {
													this.boxForm[key] = item.value == '1' ? true : false;
												} else {
													this.boxForm[key] = item.value;
												}
											}
										}
									} else if (this.equipTypeCode == 'CS') { //充电堆
										for (const key in this.boxForm2) {
											if (key == item.id) {
												this.boxForm2[key] = item.value;
											}
										}
									}
									break;
								case '1':
									if (item.id == "06010049") {
										this.operateForm.url = item.value;
									}
									if (item.id == "06010050") {
										this.operateForm.port = item.value;
									}
									break;
							}
						});
					});
			},
			// 设置参数
			doSetting(isChecked) {
				this.$Toast.loading('设置中~')
				let datas = [];
				for (const key in isChecked) {
					let val = isChecked[key];
					if (val === true) {
						val = '1';
					}
					if (val === false) {
						val = '0';
					}
					datas.push({
						id: key,
						value: val
					});
				}
				let params = {
					entitys: datas,
					equipId: this.equipId,
				};
				equipment("/operate/param/write", "post", params)
					.then((res) => {
						this.$Toast.none(res.message);
						if (res.code == 200) {
							for (const key in this.checkList) {
								this.$set(this.checkList, key, false)
							}
							let datas = res.data;
							datas.forEach((item) => {
								if (this.equipTypeCode == 'EC') { //换电柜
									for (const key in this.boxForm) {
										if (item.id == "06010032") item.value = +item.value;
										if (key == item.id) {
											if (key == '06010014' || key == '06010015' || key ==
												'06010023' ||
												key == '06010008') {
												this.boxForm[key] = item.value == '1' ? true : false;
											} else {
												this.boxForm[key] = item.value;
											}
										}
									}
								} else if (this.equipTypeCode == 'CS') { //充电堆
									for (const key in this.boxForm2) {
										if (key == item.id) {
											this.boxForm2[key] = item.value;
										}
									}
								}
							})
						}
					})
					.catch((err)=>{
						console.log(err)
						this.$Toast.none(err.message);
					});
			},
			// 运营平台链接参数
			doRunParam() {
				if (!this.operateForm.url) {
					this.$Toast.none('请输入请输入服务地址');
					return;
				} else if (!this.operateForm.port) {
					this.$Toast.none('请输入端口');
					return;
				} else if (!this.operateForm.username) {
					this.$Toast.none('请输入用户名');
					return;
				} else if (!this.operateForm.password) {
					this.$Toast.none('请输入密码');
					return;
				}
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确认要设置运营平台链接参数吗？',
					success(res) {
						if (res.confirm) {
							that.doSetRunParam();
						}
					}
				})
			},
			doSetRunParam() {
				this.$Toast.loading('设置中~')
				equipment(
						`/control/op/connectionparam/${this.equipId}`,
						"post", {
							...removeNullUndefined(this.operateForm)
						}
					)
					.then((res) => {
						if (res.code == 200) {
							this.$Toast.success(res.message);
						}
					}).catch(err=>{
						this.$Toast.success(err.message);
					})
			},
			levelChange(e) {
				if (e) {
					this.fileType = this.logOption.find(
						(item) => item.value == e
					).fileType;
				}
			},
			isTract() {
				if (!this.ruleForm.logExtractParam.level) {
					this.$Toast.none('请选择日志类型');
					return;
				} else if (!this.ruleForm.logExtractParam.startTime) {
					this.$Toast.none('请选择开始时间');
					return;
				} else if (!this.ruleForm.logExtractParam.endTime) {
					this.$Toast.none('请选择结束时间');
					return;
				} else if (!this.ruleForm.receiveEmail) {
					this.$Toast.none('请输入接收日志邮箱');
					return;
				} else {
					let that = this;
					uni.showModal({
						title: '提示',
						content: '确认要提取日志吗？',
						success(res) {
							if (res.confirm) {
								that.doTractLog();
							}
						}
					})
				}
			},
			doTractLog() {
				this.$Toast.loading('提取中~');
				let params = JSON.parse(JSON.stringify(this.ruleForm));
				params.id = this.equipId;
				params.equipClassify = this.equipTypeCode;
				params.logExtractParam.filename = this.equipCode + `_${params.logExtractParam.startTime}` +
					`_${params.logExtractParam.endTime}` + `_${params.logExtractParam.level}${this.fileType}`
				delete params.equipCode;
				let datas = {
					...params
				};
				datas.logExtractParam.startTime = new Date(datas.logExtractParam.startTime).getTime();
				datas.logExtractParam.endTime = new Date(datas.logExtractParam.endTime).getTime();
				
				logextrace('/insert', 'post', datas).then(res => {
					this.$Toast.none(res.message);
					this.resetLog();
				});
			},
			// 日志 重置
			resetLog() {
				this.ruleForm = {
					equipCode: "",
					equipClassify: "",
					receiveEmail: "",
					logExtractParam: {
						startTime: "",
						endTime: "",
						level: "",
						filename: "",
					},
				};
				this.fileType = "";
			},
			async getModelOption() {
				const datas = await models('/datails', 'post');
				this.modelOption = datas.data.map(item => {
					return {
						text: item.name,
						value: item.id
					}
				});
			},
			moveToLocation() {
				let that = this;
				let gcj = GPS.gcj_encrypt(that.dialogForm.lat, that.dialogForm.lng);
				uni.chooseLocation({
					latitude: gcj.lat || '',
					longitude: gcj.lon || '',
					success(res) {
						that.dialogForm.address = res.address;
						let wgs = GPS.gcj_decrypt_exact(res.latitude, res.longitude);
						that.dialogForm.lat = wgs.lat;
						that.dialogForm.lng = wgs.lon;
						that.getCity();
					},
					//错误信息
					fail(err) {
						console.log(err);
					}
				})
			},
			getCity() {
				let that = this;
				let pas = {
					lon: this.dialogForm.lng,
					lat: this.dialogForm.lat,
					ver: 1
				};
				uni.request({
					// header: {
					// 	"Content-Type": "application/text"
					// },
					//注意:这里的key值需要高德地图的 web服务生成的key  只有web服务才有逆地理编码
					url: 'https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=' + that.dialogForm.lng +
						',' +
						that.dialogForm.lat +
						`&key=${AMAP_KEY}&radius=1000&extensions=all`,
					// url: `https://api.tianditu.gov.cn/geocoder?postStr=${JSON.stringify(pas)}&type=geocode&tk=${mapKy}`,
					success(res) {
						if (res.statusCode == 200) {
							that.dialogForm.regionCode = res.data.regeocode.addressComponent.adcode;
							// let address = res.data.result.addressComponent;
							// that.dialogForm.regionCode = address.county_code.slice(address.county_code.length - 6);
						} else {
							console.log("获取信息失败，请重试！")
						}
					}
				});
			},
			isEditEquip() {
				let that = this;
				// if (!this.dialogForm.equipModelId) {
				// 	this.$Toast.none('请选择设备型号');
				// 	return;
				// } else if (!this.dialogForm.status && this.dialogForm.status != 0) {
				// 	this.$Toast.none('请选择业务状态');
				// 	return;
				// } else if (!this.dialogForm.address) {
				// 	this.$Toast.none('请选择详细地址');
				// 	return;
				// } else {

				// }
				uni.showModal({
					title: '提示',
					content: '确定要编辑设备情况信息吗？',
					success(res) {
						if (res.confirm) {
							that.doEditEquip();
						}
					}
				})
			},
			doEditEquip() {
				this.$Toast.loading('修改中~');
				let param = {
					...this.dialogForm
				};
				let {
					address,
					equipModelId,
					id,
					lat,
					lng,
					operatorId,
					organizationId,
					regionCode,
					status,
				} = param;
				equipment(
						"/update",
						"post", {
							address,
							equipModelId,
							id,
							lat,
							lng,
							operatorId,
							organizationId,
							regionCode,
							status,
						}
					)
					.then((res) => {
						this.$Toast.none(res.message);
					});
			},
			// 获取部件
			getPartType() {
				partType(`/list?equipTypeCode=${this.equipTypeCode}`, 'get').then(res => {
					if (res.code == 200) {
						this.partOption = res.data.map(item => {
							return {
								text: item.name,
								value: item.code
							}
						});
					}
				});
			},
			// 获取版本
			getVersion(partType) {
				softwareVersion(`/all?partType=${partType}`, 'get').then(res => {
					if (res.code == 200) {
						this.versionOption = res.data;
						this.versionOption.forEach(item => {
							item.text = item.version;
							item.value = item.id
						})
					}
				});
			},
			partTypeChange(e) {
				if (e) this.getVersion(e);
				this.updateForm.softwareVersionId = "";
				this.currentVersion = {};
				this.versionOption = [];
			},
			versionChange(e) {
				if (e) {
					this.currentVersion = this.versionOption.find(item => item.id == e);
				}
			},
			isUpdate() {
				let that = this;
				if (!this.updateForm.partType) {
					this.$Toast.none('请选择升级部件');
					return;
				} else if (!this.updateForm.softwareVersionId) {
					this.$Toast.none('请选择升级版本');
					return;
				} else {
					uni.showModal({
						title: '提示',
						content: '确定要升级吗？',
						success(res) {
							if (res.confirm) {
								that.doUpdate();
							}
						}
					})
				}
			},
			// 升级
			doUpdate() {
				this.$Toast.loading('升级中~');
				this.updateResult = {};
				updated(`/upgrade/${this.equipId}?softwareVersionId=${this.updateForm.softwareVersionId}`,
					'post').then(res => {
					if (res.code == 200) {
						this.$Toast.none(res.message);
						this.updateResult = res.data;
					}
				}).catch((err) => {
					this.$Toast.none(err.message);
				});
			},
			// 查询版本
			isSearchVersion() {
				if (!this.updateForm.partType) {
					this.$Toast.none('请选择部件类型');
					return;
				}
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确定要查询版本吗？',
					success(res) {
						if (res.confirm) {
							that.doSearchUpdate();
						}
					}
				})
			},
			doSearchUpdate() {
				equipment(`/version/list/${this.equipId}?partType=${this.updateForm.partType}`, 'post').then(res => {
					if (res.code == 200) {
						let datas = res.data;
						this.$set(this.updateResult, 'equipSoftwareVersions', datas)
					}
				})
			},
			showHelp() {
				if (!this.updateForm.softwareVersionId) {
					this.$Toast.none('请选择升级版本');
					return;
				}
				uni.showModal({
					title: '升级内容',
					content: this.currentVersion.remark,
					showCancel: false,
					showConfirm: false,
					success: function(res) {
						if (res.confirm) {} else if (res.cancel) {}
					}
				});
			},
			endTimeChange() {
				let endTime = new Date(this.ruleForm.logExtractParam.endTime).getTime();
				let startTime = new Date(this.ruleForm.logExtractParam.startTime).getTime();
				if (endTime < startTime) {
					this.ruleForm.logExtractParam.startTime = "";
				}
			},
			onKeyInput(e, key) {
				let value = e.target.value.replace(/\D/g, '');
				this.boxForm[key] = value;
			},

			operateChange(e) {
				if (e == 0) {
					this.extractForm.startDate = "";
					this.extractForm.tractDate = [];
				}
			},
			//将时分转为时间戳
			time_to_sec(time) {
				if (time !== null) {
					var s = "";
					var hour = time.split(":")[0];
					var min = time.split(":")[1];
					s = Number(hour * 3600) + Number(min * 60);
					return s;
				}
			},

			isAddExtract() {
				let that = this;
				if (!this.extractForm.cameraExtractParam.value) {
					this.$Toast.none('请选择操作指令~');
					return;
				}
				if (this.extractForm.cameraExtractParam.value != '0' && !this.extractForm.startDate) {
					this.$Toast.none('请选择提取日期~');
					return;
				}
				if (this.extractForm.startDate && this.extractForm.tractDate.length != 2) {
					this.$Toast.none('请选择提取时间~');
					return;
				}
				if (this.time_to_sec(this.extractForm.tractDate[0]) - this.time_to_sec(this.extractForm.tractDate[1]) >
					0) {
					this.$Toast.none('开始时间应小于结束时间~');
					return;
				}

				uni.showModal({
					title: '提示',
					content: '确定要新增吗？',
					success(res) {
						if (res.confirm) {
							that.doAddExtract();
						}
					}
				})
			},
			doAddExtract() {
				this.$Toast.loading('新增中~');
				let startTime = this.extractForm.startDate + ' ' + this.extractForm.tractDate[0] + ':00';
				let endTime = this.extractForm.startDate + ' ' + this.extractForm.tractDate[1] + ':00';
				let params = {
					equipId: this.equipId,
					cameraExtractParam: {
						value: this.extractForm.cameraExtractParam.value,
						startTime: new Date(startTime).getTime(),
						endTime: new Date(endTime).getTime()
					},
				};
				equipment('/cameraextract/insert', "post", {
					...removeNullUndefined(params)
				}).then(res => {
					this.$Toast.none(res.message);
				});
			},
			showDatePicker() {
				this.$refs.datePickerRef.show();
			},
			freeStartChange(e) {
				let value = e.detail.value;
				this.$set(this.extractForm.tractDate, 0, value)
			},
			freeEndChange(e) {
				let value = e.detail.value;
				this.$set(this.extractForm.tractDate, 1, value)
			},
			clearOccupyTime() {
				this.extractForm.tractDate = [];
			},
		},
	}
</script>
<style lang="scss">
	::v-deep .uni-date__x-input {
		font-size: 10px !important;
	}
</style>
<style lang="scss" scoped>
	@import "@/static/css/common.scss";

	.params {
		.param-content {
			padding: 0 20rpx 20rpx;

			.param-one {
				line-height: 92rpx;
				@include flexLayout(center, flex-start);
				border-bottom: 2rpx solid #E5E5E5;
				font-size: 28rpx;
				color: #333333;

				text {
					width: 240rpx;
					text-align: right;
					margin-right: 20rpx;
				}

				.labels {
					width: 130rpx;
				}

				.update-labels {
					width: 180rpx;
				}

				.inputs {
					width: calc(100% - 130rpx);
				}

				.address {
					line-height: 52rpx;
					width: calc(100% - 130rpx);
				}

				.update-inputs {
					width: calc(100% - 180rpx);
					text-align: left;
				}

				.mails {
					width: 180rpx;
				}

				.sliders {
					width: calc(100% - 250rpx);
				}

				.help_icon {
					margin-top: 12rpx;
				}

				.textarea-sn {
					width: 55%;
					max-height: 80rpx;
					border-width: 2rpx 20rpx;
					border-style: solid;
					border-color: #F7F7F7;
					line-height: 40rpx;
					font-size: 26rpx;
					padding: 20rpx 0;
				}
			}

			.extract-one {
				.mails {
					width: 150rpx;
				}
			}

			.versions {
				min-height: 200rpx;
				border: 2rpx solid #efefef;
				padding: 20rpx;
			}

			.log_tips {
				color: red;
				font-size: 32rpx;
				margin: 30rpx 0 20rpx;
			}

			.operate_btns {
				text-align: center;
				margin-top: 20rpx;

				.set_btn {
					background-color: #51b7b9;
					margin-left: 40rpx;
					color: #FFFFFF;
				}

				.update_btn {
					margin-left: 60%;
				}
			}

			.update_btns {
				text-align: right;
			}
		}
	}
</style>